<?php
/**
 * Created by JetBrains PhpStorm.
 * User: Alejandro Casas
 * Date: 1/28/13
 * Time: 12:45 PM
 * To change this template use File | Settings | File Templates.
 */
if (!isset ($_COOKIE[ini_get('name')])) {
    session_set_cookie_params(0, '/');
    session_name('name');
    session_start();
}
require "../Connectors/CommonWSSearch.php";
require "../Classes/Sport.php";
$searchws = new SearchWS();

if(isset ($_GET['oper']))
{
    $oper=$_GET['oper'];
    if($oper=="test")
    {
        echo $searchws->testGet($_GET['param']);
    }
    elseif($oper=="SearchUsers")
    {
        if($_GET['param']=="" || $_GET['param']==null)
        {
            echo("<script type=\"text/javascript\" >

				alert(\"The search cannot be empty\");
				location.replace(\"../html/home.php\");
		</script>");
        }
        else
        {
            $r=($searchws->SearchUsers($_GET['param']));
            // print_r($r);
            $empty=true;
            foreach($r->body as $u)
            {
                $empty=false;
                echo "<h1>-----------------------------</h1>";
                echo "Mail: ".$u->mail."</br>";
                echo "Name: ".$u->name;
            }
            if($empty)
            {
                echo 'Woops No results! GO BACK! and search for some shorter string! :/';
            }
        }

    }
}
else{
    $oper=$_POST['oper'];
    if($oper=="test")
    {
        echo $searchws->testPOST($_POST['param']);
    }
    if($oper=="json")
    {
        echo $searchws->testJSON(new Sport($_POST['param']));
    }
    if($oper=="searchPlayers")
    {

        $r=$searchws->SearchPlayers($_SESSION['session_mail'],$_POST['deporte'],$_POST['ciudad'],$_POST['pais'],$_POST['privacidad'],"","");



        foreach($r->body as $v)
        {

            ?>
        <div class="perfilItem">
            <div class="shareTiny">
                <a href="#" class="fb"></a>
                <a href="#" class="tw"></a>
            </div>
            <img src="img/perfil/img1.jpg" width="120" height="114" alt="Fulanito de Tales">
            <div class="right">
                <?php
                $ranking="N/A";
                if(count($v->sports_level)>0){

                 }
                ?>
                <span><strong>Calification:</strong> <?php  echo $ranking; ?></span><br>
                <!--<span><strong>Fecha ini:</strong> 05/11/12</span><br>
                <span><strong>Fecha fin:</strong> 08/12/12</span>-->
            </div>
            <div class="clear"></div>
            <div class="text">
                <strong>Nombre:</strong> <?php echo $v->name;  ?><br>
                <strong>Genero:</strong> <?php echo $v->gender;  ?><br>
                <strong>Deporte Principal:</strong> <?php echo $v->sports[0];  ?><br>
            </div>
            <div class="setsBox">
                <a href="perfil.php" class="btn" ><span class="icon icon3"></span><span class="txt">Ver Perfil</span></a>
                <a href="actividadInvitar.php" class="btn opencBox" ><span class="icon icon2"></span><span class="txt">Invitar actividad</span></a>
                <div class="sep"></div>
                <a href="actividadReportar.php" class="btn opencBox" ><span class="icon icon4"></span><span class="txt">Reportar</span></a>
            </div>
        </div>

        <?php
        }


    }
}


